<?php

/**
 * 语言包
 *
 * @author JiangJian <silverd@sohu.com>
 * $Id: Language.php 156 2012-11-08 01:37:15Z silverd30@gmail.com $
 */

class Com_Language
{
    private static $_langs;
    private static function _load()
    {
        if (self::$_langs === null) {
            self::$_langs = include LANG_PATH . CUR_LANG . '.php';
        }
    }

    public static function get($string, $data = null)
    {
        // 加载语言包
        self::_load();

        if (isset(self::$_langs[$string])) {
            $string = self::$_langs[$string];
        }

        if (!$data) {
            return $string;
        }

        // 替换变量
        return vsprintf($string, (array) $data);
    }
}